package vm

import (
	"os"
	"fmt"
	"kumachan/interpreter/runtime/rt"
)

func tryDumpAsm(path string, p *rt.Program) {
	if path == "" {
		return
	}
	var log = func(e error) {
		fmt.Fprintf(os.Stderr, "failed to dump asm: %s", e.Error())
	}
	// 1. open
	var f, err1 = os.OpenFile(path, os.O_CREATE | os.O_TRUNC | os.O_WRONLY, 0644)
	if err1 != nil { log(err1); return }
	// 2. write
	var _, err2 = f.WriteString(p.String())
	if err2 != nil { log(err2); return }
	// 3. close
	var err3 = f.Close()
	if err3 != nil { log(err3); return }
}


